//
//  JCLStatusCell.swift
//  WeiBo
//
//  Created by DDC on 2017/9/15.
//  Copyright © 2017年 DDC. All rights reserved.
//

import UIKit

class JCLStatusCell: UITableViewCell {
    
    
    var viewModel:JCLStatusViewModel? {
        didSet {
            
            //用户昵称
            userNameLabel.text = viewModel?.status.user?.screen_name
            //会员图标
            memberIconView.image = viewModel?.memberIcon
            //认证图标
            renZhenIconView.image = viewModel?.grassroot
            //用户头像
            userIconView.jcl_setImageView(urlString: viewModel?.status.user?.profile_image_url, placeholderImage: UIImage(named: "avatar_default_big")!,isAvater: true)
//            userIconView.layer.cornerRadius = userIconView.bounds.width * 0.5
//            userIconView.layer.masksToBounds = true
            
            toolBar.viewModel = viewModel
            
            //测试配图视图的高度
            pictureView.viewModel = viewModel
            // pictureView.pictureHeightCons.constant = viewModel?.pictureSize.height ?? 0
//            picTopCons.constant = 0/
            
            //设置配图视图的模型
            // 测试4张图片的显示样式
            /*
             
             if (viewModel?.status.pic_urls?.count)! > 4 {
             
             // 移除多余的数据
             var picurls = viewModel?.status.pic_urls
             picurls?.removeSubrange(((picurls?.startIndex)! + 4)..<(picurls?.endIndex)!)
             pictureView.urls = picurls
             
             } else {
             
             pictureView.urls = viewModel?.status.pic_urls
             }
             */
            
            pictureView.urls = viewModel?.picURLs
            
            /// 设置微博转发内容的属性文本
            retweetedLabel?.attributedText = viewModel?.retweetedAttrText
            /// 微博正文的属性文本
            weiBoLabel.attributedText = viewModel?.statusAttrText
            /// 设置来源文本
            sourceLabel.text = viewModel?.status.source
            /// 设置创建时间文本
            timeLabel.text = viewModel?.status.createDate?.jcl_description
        
 
        }
    }

    /// 用户头像
    @IBOutlet weak var userIconView: UIImageView!
    
    /// 用户名
    @IBOutlet weak var userNameLabel: UILabel!
    
    /// 会员图标
    @IBOutlet weak var memberIconView: UIImageView!
    
    /// 发布时间
    @IBOutlet weak var timeLabel: UILabel!
    
    /// 发布来源
    @IBOutlet weak var sourceLabel: UILabel!
    
    /// 认证图标
    @IBOutlet weak var renZhenIconView: UIImageView!
    
    /// 微博正文
    @IBOutlet weak var weiBoLabel: JCLLabel!
    
    /// 底部工具栏
    @IBOutlet weak var toolBar: JCLStatusToolBar!
    
    /// 配图视图
    @IBOutlet weak var pictureView: JCLStatusPictureView!
    
    /// 配图视图顶部约束
    @IBOutlet weak var picTopCons: NSLayoutConstraint!
    
    /// 转发微博的正文
    @IBOutlet weak var retweetedLabel: JCLLabel?
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        /// 栅格化设置  优化性能
        /// 离屏渲染--异步绘制
        self.layer.drawsAsynchronously = true
        /// 开启栅格化
        /// 栅格化异步绘制之后,会生成一张独立的图片,当cell在滚动的时候，实际上滚动的是这张图
        /// cell的优化  要尽量减少图层的数量，相当于就只有一层
        /// 停止滚动之后，可以接收监听
        self.layer.shouldRasterize = true
        /// 栅格化渲染尺寸，必须指定分辨率
        self.layer.rasterizationScale = UIScreen.main.scale
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
